<template>
	<view>
		<view style="height: 18upx;"></view>
		<view class="form-view">
			<view class="form-item" style="padding-bottom: 18upx;">
				<view class="form-label">
					<view>头像</view>
					<view class="label-desc">{{userInfo.avatarImg ? 1 : 0}}/1</view>
				</view>
				<view @click="onChooseImage" class="form-content" style="justify-content: flex-end;">
					<image v-if="userInfo.avatarImg" :src="`${IMG_URL}${userInfo.avatarImg}`" class="uploading"></image>
					<image v-else src="/static/personal-uploading.png" class="uploading"></image>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">注册手机</view>
				<view class="form-content">
					<view class="form-item-text">{{userInfo.phoneNumber}}</view>
					<image src="/static/lock-icon.png" class="lock-icon"></image>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">顾问工号</view>
				<view class="form-content">
					<view class="form-item-text">{{userInfo.advisoryNumber}}</view>
					<image src="/static/lock-icon.png" class="lock-icon"></image>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">会员等级</view>
				<view class="form-content">
					<view class="form-item-text">{{userInfo.memberLevel.name}}</view>
					<image src="/static/lock-icon.png" class="lock-icon"></image>
				</view>
			</view>
		</view>
		<view class="form-view">
			<view class="form-item">
				<view class="form-label">账户名称</view>
				<navigator :url="`/pages/authentication/authentication?authFlag=${userInfo.authFlag}`"
					hover-class="none" class="form-content" style="justify-content: flex-end;">
					<view v-if="userInfo.authFlag == '20'" class="form-item-text" style="margin-right: 22upx;">
						{{userInfo.realName}}
					</view>
					<view v-else-if="userInfo.authFlag == '30'" class="form-item-text" style="margin-right: 22upx;">
						{{userInfo.firmName}}
					</view>
					<view v-else class="form-item-text" style="color: #FF2615;margin-right: 22upx;">
						未实名
					</view>
					<uni-icons type="right" size="29upx" color="#B8ACA3"></uni-icons>
				</navigator>
			</view>
			<navigator url="/pagesMine/addressList/addressList" hover-class="none" class="form-item">
				<view class="form-label">联系地址</view>
				<view class="form-content" style="justify-content: flex-end;">
					<view class="form-item-text row" style="align-items: baseline; color: #2C1101;margin-right: 22upx;">
						<view style="font-size: 22upx;">共</view>
						<view style="margin: 0 8upx;">{{addressRows}}</view>
						<view style="font-size: 22upx;">个</view>
					</view>
					<uni-icons type="right" size="29upx" color="#B8ACA3"></uni-icons>
				</view>
			</navigator>
			<navigator url="/pagesMine/bankingList/bankingList" hover-class="none" class="form-item">
				<view class="form-label">银行账号</view>
				<view class="form-content" style="justify-content: flex-end;">
					<view class="form-item-text row" style="align-items: baseline;color: #2C1101;margin-right: 22upx;">
						<view style="font-size: 22upx;">共</view>
						<view style="margin: 0 8upx;">{{bankRows}}</view>
						<view style="font-size: 22upx;">个</view>
					</view>
					<uni-icons type="right" size="29upx" color="#B8ACA3"></uni-icons>
				</view>
			</navigator>
		</view>
		<view style="height: 260upx;"></view>
		<FloatView>
			<FloatButton @click="updateUserInfo">保存</FloatButton>
		</FloatView>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bankRows: 0,
				addressRows: 0,
				userInfo: {
					avatarImg: '',
					phoneNumber: '',
					realName: '',
					advisoryNumber: '', // 顾问编号（工作流员工号）
					memberLevel: {
						name: ''
					}
				}
			}
		},
		onLoad() {
			this.getUserInfo()
		},
		onShow() {},
		methods: {
			async onChooseImage() {
				const image = await uni.$util.chooseImage(1)
				if (!image.length) return
				uni.$util.showLoading('上传中...')
				const res = await uni.$api.uploadFile(image[0]).finally(uni.finally)
				this.userInfo.avatarImg = res.data.fileObjectName
			},
			async updateUserInfo() {
				uni.$util.showLoading('修改中...')
				await uni.$api.updateUserInfo({
					avatarImg: this.userInfo.avatarImg
				}).finally(uni.finally)
				uni.$util.showSuccess()
			},
			async getUserInfo() {
				const res = await uni.$api.getUserInfo()
				this.userInfo = res.data
				this.getBankList()
				this.getAddressList()
			},
			async getBankList() {
				const res = await uni.$api.getBankList()
				this.bankRows = res.data.totalRows
			},
			async getAddressList() {
				const res = await uni.$api.getBankList()
				this.addressRows = res.data.totalRows
			},
		}
	}
</script>

<style scoped lang="scss">
	.form-view {
		width: 707rpx;
		margin: 0 auto;
		padding: 0 40upx;
		background: #FFFFFF;
		border-radius: 14rpx;

		.form-item {
			width: 100%;
			padding: 34upx 0;
			@extend .row-between;

			.form-label {
				width: 160upx;
				font-size: 29rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #B8ACA3;

				.label-desc {
					font-size: 22rpx;
					color: #B8ACA3;
				}
			}

			.form-content {
				width: calc(100% - 160upx);
				@extend .row-between;

				.uploading {
					width: 92upx;
					height: 92upx;
					border-radius: 4upx;
				}

				.form-item-text {
					font-size: 29rpx;
					font-weight: 400;
					color: #2C1101;
				}

				.lock-icon {
					width: 33upx;
					height: 33upx;
				}
			}
		}

		.form-item+.form-item {
			border-top: 1px solid #E9E9F4;
		}
	}

	.form-view+.form-view {
		margin-top: 18upx;
	}
</style>